# 使用Maven 3.9.2和JDK 17构建阶段
FROM maven:3.9.3-eclipse-temurin-17 AS build
WORKDIR /mall4j-master/

COPY / /mall4j-master

# COPY settings.xml pom.xml /mall4j-master/
# 先安装父POM到本地仓库
RUN mvn -f pom.xml clean install -N
# 构建整个项目
RUN mvn clean install -DskipTests
# 单独构建admin模块
RUN mvn -pl yami-shop-admin clean package -DskipTests

# 使用OpenJDK 17运行阶段
FROM openjdk:17.0.2

WORKDIR /opt/projects/mall4j

# 从构建阶段复制构建好的jar包到运行阶段的工作目录
COPY --from=build /mall4j-master/yami-shop-admin/target/yami-shop-admin-0.0.1-SNAPSHOT.jar ./yami-shop-admin-0.0.1-SNAPSHOT.jar

# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 启动命令
CMD ["java", "-jar", "-Xms512m", "-Xmx512m", "-Xss256k", "-XX:SurvivorRatio=8", "-Dspring.profiles.active=prod", "yami-shop-admin-0.0.1-SNAPSHOT.jar"]
